import Vue from 'vue'
import Router from 'vue-router'

import HomePage from './modules/HomePage'
import AuxiliaryMonitor from './modules/AuxiliaryMonitor'
import OperationMonitor from './modules/OperationMonitor'
import OnlineMonitor from './modules/OnlineMonitor'
import Locks from './modules/Locks'
import JointInspection from './modules/JointInspection'
import VideoMonitor from './modules/VideoMonitor'
import WarningToSolve from './modules/WarningToSolve'
import ParameterManagement from './modules/ParameterManagement'
import IntelligentControlDetil from './modules/IntelligentControlDetil'
import SystemManagement from './modules/SystemManagement'
Vue.use(Router)



export default new Router({
  // mode: 'history',
  // base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/index.vue'),
    },
    HomePage,
    AuxiliaryMonitor,
    OperationMonitor,
    OnlineMonitor,
    Locks,
    JointInspection,
    VideoMonitor,
    WarningToSolve,
    ParameterManagement,
    IntelligentControlDetil,
    SystemManagement,
    {
      path: '/vi',
      name: 'vi',
      component: () => import('../views/videoDome.vue'),
    },
    {
      path: '/netManageMent',
      name: 'netManageMent',
      component: () => import('../views/netManageMent/index.vue'),
    },
  ]
})

/*
* Preventing "NavigationDuplicated" errors in console in Vue-router >= 3.1.0
* https://github.com/vuejs/vue-router/issues/2881#issuecomment-520554378
* */

const routerMethods = ['push', 'replace'];

routerMethods.forEach((method: string) => {
  const originalCall = (Router.prototype as any)[method];
  // tslint:disable-next-line:space-before-function-paren
  (Router.prototype as any)[method] = function (location: any, onResolve: any, onReject: any): Promise<any> {
    if (onResolve || onReject) {
      return originalCall.call(this, location, onResolve, onReject);
    }
    return (originalCall.call(this, location) as any).catch((err: any) => err);
  };
});